package com.whs.demo.application;

import com.badlogic.gdx.backends.jglfw.JglfwApplication;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.whs.demo.Demo;
import com.whs.demo.assets.Assets;
import com.whs.demo.progress.ImageRotation;
import com.whs.demo.ui.ProgressActor;

public class FlipTest
    extends Demo {

    private TextureRegion region;
    private Stage stage;
    private OrthographicCamera camera;
    private Viewport viewport;
    

    @Override
    public void create() {
        super.create();
        Assets.init();
        Assets.loadAll();
        Assets.finishLoading();
        Assets.initTestAtlas();
        region = Assets.testAtlas.findRegion("world1");
        stage = new Stage();
        camera = new OrthographicCamera(WIDTH, HEIGHT);
        camera.position.set(WIDTH / 2, HEIGHT / 2, 0);
        viewport = new ScreenViewport(camera);
        viewport.setCamera(camera);
        stage.setViewport(viewport);
        camera.update();
        
        // 正常
        LabelStyle labelStyle = new Label.LabelStyle(Assets.font, Color.RED);
        Image image = new Image(region);
        image.setOrigin(Align.center);
        image.setPosition(0, 550F);
        Label label = new Label("image", labelStyle);
        label.setPosition(image.getX() + (image.getWidth() - label.getWidth()) / 2, image.getY() + image.getHeight());
        label.setAlignment(Align.center);
        label.setFontScale(0.5F);
        label.setScale(0.5F);
  
        
//        stage .addActor(label);
//        stage.addActor(image);
        
        // 水平翻转
        TextureRegion region1 = new TextureRegion(region);
        region1.setU(region.getU2());
        region1.setU2(region.getU());
        Image image1 = new Image(region1);
        image1.setPosition(image.getWidth() + 10, 550F);
        Label label1 = new Label("image1", labelStyle);
        label1.setPosition(image1.getX() + (image1.getWidth() - label1.getWidth()) / 2, image1.getY() + image1.getHeight());
        label1.setAlignment(Align.center);
        label1.setFontScale(0.5F);
        label1.setScale(0.5F);
//        stage.addActor(image1);
//        stage.addActor(label1);
//        
        
        // 水平翻转
        TextureRegion region2 = new TextureRegion(region);
        region2.setV(region.getV2());
        region2.setV2(region.getV());
        Image image2 = new Image(region2);
        image2.setPosition(0 , 300F);
        Label label2 = new Label("image2", labelStyle);
        label2.setPosition(image2.getX() + (image2.getWidth() - label2.getWidth()) / 2, image2.getY() + image2.getHeight());
        label2.setAlignment(Align.center);
        label2.setFontScale(0.5F);
        label2.setScale(0.5F);
//        stage.addActor(image2);
//        stage.addActor(label2);
        
        
        
        // 水平翻转
        TextureRegion region3 = new TextureRegion(region);
        region3.flip(true, false);
        Image image3 = new Image(region3);
        image3.setPosition(image3.getWidth() + 10F , 300F);
        Label label3 = new Label("image3", labelStyle);
        label3.setPosition(image3.getX() + (image3.getWidth() - label3.getWidth()) / 2, image3.getY() + image3.getHeight());
        label3.setAlignment(Align.center);
        label3.setFontScale(0.5F);
        label3.setScale(0.5F);
//        stage.addActor(image3);
//        stage.addActor(label3);
        
        /**
         * 图片的旋转
         */
        ImageRotation image4 = new ImageRotation();
        image4.setOrigin(Align.center);
        image4.setRotation(60);
        image4.setPosition(0 + 10F , 50F);
        Label label4 = new Label("image4", labelStyle);
        label4.setPosition(image4.getX() + (image4.getWidth() - label3.getWidth()) / 2, image4.getY() + image4.getHeight());
        label4.setAlignment(Align.center);
        label4.setFontScale(0.5F);
        label4.setScale(0.5F);
//        stage.addActor(image4);
//        stage.addActor(label4);       
        ProgressActor progress = new ProgressActor();
        progress.setPosition(100, 700);
        stage.addActor(progress);
    }

    @Override
    public void render() {

        super.render();
        stage.act();
        stage.draw();
    }

    @Override
    public void dispose() {
        // TODO Auto-generated method stub
        super.dispose();

        stage.dispose();
        Assets.dispose();
    }

    public static void main(String[] args) {
        new JglfwApplication(new FlipTest(), "进度条 - By WHS", WIDTH , HEIGHT);
    }

}
